<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="nav_bar">
    <ul class="layui-nav" lay-filter="">
        <li class="layui-nav-item"><a href="/index.jsp">主页</a></li>
        <li class="layui-nav-item">
            <a>联系我们</a>
            <dl class="layui-nav-child"> <!-- 二级菜单 -->
                <dd><a href="">电话(phone)：13427546537</a></dd>
                <dd><a href="">邮箱(email)：718681050@qq.com</a></dd>
            </dl>
        </li>
    </ul>
    <ul class="layui-nav layui-layout-right">
        <li id="worker_center" class="layui-nav-item"><a id="worker_cmd" href="/login.jsp">${worker.name}【${worker.role.roleName}】</a></li>
    </ul>
</div>

<script>
    layui.use('element', function(){
        var element = layui.element;
    });

    var worker_center=$('#worker_center');
    var worker_cmd=$('#worker_cmd');
    if(worker_cmd.text()=="【】"){
        worker_cmd.text("登录");
    }else{
        worker_cmd.attr("href","/back/manage");
        $('<dl class="layui-nav-child">' +
            '<dd><a id="worker_Info" href="javascript:;" data-method="workerInfo">个人信息</a></dd>' +
            '<dd><a id="modifyPsw" href="javascript:;" data-method="modifyPassword" >修改密码</a></dd>' +
            '<dd><a id="logout_btn" href="javascript:;" data-method="offset" data-type="auto">退出登录</a></dd>' +
            '</dl>').appendTo(worker_center);
    }
    

    layui.use('layer',function () {
        var $ = layui.jquery, layer = layui.layer;
        var active={
            workerInfo:function (othis) {
                layer.open({
                    type: 2,
                    title:'个人信息',
                    skin: 'layui-layer-lan',
                    area:['420px','600px'],
                    content: ['${pageContext.request.contextPath}/worker/workerInfo','no'],
                    btn:'关闭页面'
                });
            }
            ,modifyPassword:function (othis) {
                layer.open({
                    type:2,
                    title:'修改密码',
                    skin: 'layui-layer-lan',
                    area:['330px','390px'],
                    content: ['${pageContext.request.contextPath}/worker/modifyPassword/${worker.workerId}','no'],
                    btn:'关闭页面'
                })
            }
            ,offset: function(othis){
                var type = othis.data('type')
                    ,text = othis.text();
                layer.open({
                    type: 1
                    ,title:"提示"
                    ,offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    ,id: 'layerDemo'+type //防止重复弹出
                    ,content: '<div style="padding: 20px 100px;">确定要退出吗?</div>'
                    ,btn: ['确定','取消']
                    ,btnAlign: 'c' //按钮居中
                    ,shade: 0 //不显示遮罩
                    ,yes: function(){
                        layer.close();
                        window.location.href="${pageContext.request.contextPath}/worker/logout";
                    }
                    ,btn2:function () {
                        layer.close();
                    }
                });
            }
        }

        $('#logout_btn').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
        $('#worker_Info').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
        $('#modifyPsw').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
    });

</script>
